﻿package com.nianzhen.student.fra;

import java.util.ArrayList;

import me.maxwin.view.XListView;

import com.nianzhen.db.Jobitem;
import com.nianzhen.job.JobDetail;
import com.nianzhen.job.Search;
import com.nianzhen.recruitment.BaseNetFragment;
import com.nianzhen.recruitment.BaseNetFragmentActivity;
import com.nianzhen.recruitment.R;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * 职位界面
 * @author nianzhen
 * 2015年4月1日20:40:07
 */
public class Job  extends BaseNetFragment{
	private String companytest="测试公司";
	private String jobtest="测试职位";
	private XListView mListView;
	private ArrayList<Jobitem> jobitem;
	private JobAdapter mJob;
	private int start = 0;
	private static int refreshCnt = 0;
	private TextView textView;
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		return inflater.inflate(R.layout.job, container, false);
	}

	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
		init();
	}

	private void init() {
		// TODO Auto-generated method stub
		mListView = (XListView) getView().findViewById(R.id.xListView);
		textView = (TextView ) getView().findViewById(R.id.search);
		mListView.setPullLoadEnable(true);
		jobitem=new ArrayList<Jobitem>();
		initData();//加载数据
		textView.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				//跳转到搜索详情
				Intent intent=new Intent(getActivity(),Search.class);
				startActivity(intent);
			}
		});
	}
	
	
	private void initData() {
		// TODO Auto-generated method stub
		//获取数据
		toLoadingLayout();
		
		for (int i = 0; i < 5; i++) {
			Jobitem jobitem1=new Jobitem();
			jobitem1.setCompany(companytest+(++start)+"");
			jobitem1.setJob(jobtest+(++start)+"");
			jobitem.add(jobitem1);
		}
		mJob=new JobAdapter(getActivity(), jobitem);
		mListView.setAdapter(mJob);
		mListView.setXListViewListener(pullToreFreshListener);
		mListView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				//跳到职位详情界面
				Intent intent=new Intent(getActivity(),JobDetail.class);
				startActivity(intent);		
				}
		});
	}
	
	
	private me.maxwin.view.XListView.IXListViewListener pullToreFreshListener=new me.maxwin.view.XListView.IXListViewListener(){

		@Override
		public void onRefresh() {
			// TODO Auto-generated method stub
			start = ++refreshCnt;
			jobitem.clear();
			initData();
			// mAdapter.notifyDataSetChanged();
			mJob=new JobAdapter(getActivity(), jobitem);
			mListView.setAdapter(mJob);
			onLoad();
		}

		@Override
		public void onLoadMore() {
			// TODO Auto-generated method stub
			initData();
			mJob.notifyDataSetChanged();
			onLoad();
		}
		
		private void onLoad() {
			mListView.stopRefresh();
			mListView.stopLoadMore();
			mListView.setRefreshTime("刚刚");
		}
	};
	@Override
	protected void loadData() {
		// TODO Auto-generated method stub
		
	}


	
}
